<?php

namespace falcon5\inc\Infrastructure\Services\Falcon5;

use falcon5\inc\Exceptions\RemoteServiceException;
use lucatume\DI52\ContainerException;

trait AuthTrait
{
    /**
     * @param $body
     * @return mixed
     * @throws ContainerException
     * @throws RemoteServiceException
     */
    public function validateKey($body)
    {
        $response = $this->getClient()->validateKey($body);

        $content = $response->getBody()->getContents();

        if ($response->getStatusCode() != 200) {
            throw new RemoteServiceException($content, $response->getStatusCode());
        }

        return json_decode($content, true);
    }

    /**
     * @param $body
     * @return mixed
     * @throws ContainerException
     * @throws RemoteServiceException
     */
    public function bindDomain($body)
    {
        $response = $this->getClient()->bindDomain($body);

        $content = $response->getBody()->getContents();

        if ($response->getStatusCode() != 200) {
            throw new RemoteServiceException($content, $response->getStatusCode());
        }

        return json_decode($content, true);
    }

    public function getUserSubscribe($body){
        $response = $this->getClient()->validateKey($body);

        $content = $response->getBody()->getContents();

        if ($response->getStatusCode() != 200) {
            throw new RemoteServiceException($content, $response->getStatusCode());
        }

        return json_decode($content, true);
    }
   

}